package logic

import (
	"context"
	"math/rand"
	"month2/C/rpc_C/model/redis"
	"time"

	"month2/C/rpc_C/internal/svc"
	"month2/C/rpc_C/order"

	"github.com/zeromicro/go-zero/core/logx"
)

type SmsLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewSmsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SmsLogic {
	return &SmsLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *SmsLogic) Sms(in *order.SmsRequest) (*order.SmsResponse, error) {
	code := rand.Intn(9000) + 1000
	/*sms, err := pkg.Sms(in.Tel, strconv.Itoa(code))
	if err != nil {
		return nil, err
	}
	if *sms.Body.Code != "OK" {
		return nil, fmt.Errorf(*sms.Body.Message)
	}*/
	redis.Client.Set(context.Background(), "sms"+in.Source, code, time.Hour*1)
	return &order.SmsResponse{}, nil
}
